package model;

import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;

public class Bullet {
	public enum State{
		FLY, COLLISTED, DIE
	}
	public static float SIZE = 0.2f;
	public static float SPEED = 6f;
	static final int COLLISFRAMES=8;
	float LIFEFAR= 5F;
	Rectangle bound= new Rectangle();
	Vector2 position = new Vector2();
	Vector2 position_old=new Vector2();
	Vector2 velocity = new Vector2();
	State state = State.FLY;
	int framesCollis=0;
	public Bullet(Vector2 pos,boolean isFaceleft){
		position = pos;
		position_old.set(pos.x,pos.y);
		if(isFaceleft)
		velocity.set(new Vector2(-SPEED,0));
		else 
			velocity.set(new Vector2(SPEED,0));
		bound.x=pos.x;
		bound.y=pos.y;
		bound.width = SIZE;
		bound.height= SIZE;
	}
	public void setPosition(Vector2 pos){
		position = pos;
		bound.x = pos.x;
		bound.y = pos.y;
		
	}
	public Vector2 getPosition(){
		return position;
	}
	public void setVelocity (Vector2 vel){
		velocity = vel;
	}
	public Vector2 getVelocity(){
		return velocity;
	}
	public void setState(State sta){
		state= sta;
	}
	public State getState(){
		return state;
	}
	public void update(float delta){	
		position.add(velocity.cpy().scl(delta));
		bound.x=position.x;
		bound.y=position.y;
	}
	public boolean isDisapear(){
		if(Math.abs(position.x-position_old.x)>LIFEFAR)
			return true;
		if(state.equals(State.DIE))
			return true;
		return false;
	}
	public Rectangle getBound(){
		return bound;
	}
	public void setBound(Rectangle bound){
		this.bound=bound;
	}
	public void nextCollisFrame()
	{
		if(framesCollis==COLLISFRAMES)
			state=state.DIE;
		else
			framesCollis++;
	}
	public int getFramesCollis(){
		return framesCollis;
	}
	
}
